<?php

class NCore_CURL
{
    private $connectTimeout = 1;
    private $timeout = 2;

    public function withConnectTimeout($timeout)
    {
        $this->connectTimeout = $timeout;
    }

    public function withTimeout($timeout)
    {
        $this->timeout = $timeout;
    }

    public function getURLContents($url)
    {
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        $str = curl_exec($ch);
        $error_no = curl_errno($ch);
        curl_close ($ch);
        if($error_no != 0)
        {
            if(is_int($error_no))
            {
                throw new Exception('There was an error retreiving the string contents of the url \''.$url.'\'. CURL error number:'.$error_no);
            }
            else
            {
                throw new Exception('There was an error saving the url \''.$url.'\', and the CURL error number was invalid, too.');
            }
        }
        else
        {
            return $str;
        }
    }
}

?>
